package org.dbview.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.dbview.dao.ITableInfoMapper;
import org.dbview.model.UserIndColumns;
import org.dbview.service.ITableInfoService;
import org.springframework.beans.factory.annotation.Autowired;

public class TableInfoServiceImpl implements ITableInfoService {
	private static Logger logger = Logger.getLogger(TableInfoServiceImpl.class);
	
	@Autowired
	private ITableInfoMapper tableInfoMapper;

	@Override
	public void updateTableComment(String tableName, String comment) {
		try {
			String sql = "comment on table " + tableName + " is '" + comment
					+ "'";
			tableInfoMapper.updateTableComment(sql);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
	}

	@Override
	public void updateColumnComment(String tableName, String columnName,
			String comment) {
		try {
			String sql = "comment on column " + tableName + "." + columnName
					+ " is '" + comment + "'";
			tableInfoMapper.updateColumnComment(sql);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
	}

	@Override
	public List<UserIndColumns> findIndexByTable(String tableName) {
		return tableInfoMapper.findIndexByTable(tableName);
	}

}
